package cn.tedu.straw.api.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 当前类仅用于演示授权（案例1），已作废
 */
@Deprecated
// @Configuration
// @EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig1 extends WebSecurityConfigurerAdapter {

    /**
     * <p>创建“密码加密器”对象交给Spring框架进行管理！</p>
     * <p>后续，Spring Security将吃通过自动装配的机制得到这个密码加密器！</p>
     *
     * @return 密码加密器对象
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        // 在内存中授权
        auth.inMemoryAuthentication()
                // withUser > 指定用户名
                .withUser("root")
                // password > 指定密码
                .password("1234")
                // authorities > 指定授权，方法参数值是权限标识字符串
                .authorities("/admin/list", "/admin/delete");
    }

}
